//
//  RentHouseTableViewCell.m
//  Liuhe
//
//  Created by zr on 2018/8/9.
//  Copyright © 2018年 zr. All rights reserved.
//

#import "RentHouseTableViewCell.h"


@interface RentHouseTableViewCell ()

@property (nonatomic, weak)UILabel * titleLabel;
@property (nonatomic, strong)UIImageView * leftImageView;
@property (nonatomic, weak)UILabel * contentLabel;
@property (nonatomic, weak)UILabel * moneyLabel;
@property (nonatomic, weak)UILabel * subLabel;
@property (nonatomic, weak)UIView * lineView;

@end

@implementation RentHouseTableViewCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setupUI];
    }
    
    return self;
}


- (void)setModel:(RentHouseModel *)model{
    
    _model = model;
    
    self.titleLabel.text = model.name;
    self.contentLabel.text = model.address;
    self.moneyLabel.text = [NSString stringWithFormat:@"%@元/月",model.price];
    self.subLabel.text = [NSString stringWithFormat:@"%@ %@㎡ %@",model.house,model.area,model.decorate];
    
    NSArray * arr = model.images;
    
    if (arr.count > 0) {
        
        NSURL * url = [NSURL URLWithString:arr.firstObject];
        
        [self.leftImageView sd_setImageWithURL:url];
    }
}


- (void)setupUI{
    
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.backgroundColor = WHITE_COLOR;
    
    
    UIImageView * leftImageView = [UIImageView new];
    
    leftImageView.backgroundColor = [UIColor blueColor];
    
    self.leftImageView = leftImageView;
    
    [self.contentView addSubview:self.leftImageView];
    
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.text = @"中原六仔网投平台出租";
    titleLabel.textColor = BLACK_COLOR;
    titleLabel.font = [UIFont systemFontOfSize:15 * SCREENH6];
    
    self.titleLabel = titleLabel;
    
    [self.contentView addSubview:self.titleLabel];
    
    
    UILabel * moneyLabel = [UILabel new];
    
    moneyLabel.text = @"1000元/月";
    moneyLabel.textColor = [UIColor redColor];
    moneyLabel.font = [UIFont systemFontOfSize:14 * SCREENH6];
//    moneyLabel.textAlignment = NSTextAlignmentRight;
    
    self.moneyLabel = moneyLabel;
    
    [self.contentView addSubview:self.moneyLabel];
    
    
    UILabel * contentLabel = [UILabel new];
    
    contentLabel.text = @"12345685249";
    contentLabel.textColor = ColorWithRGB(0x999999);
    contentLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    
    self.contentLabel = contentLabel;
    
    [self.contentView addSubview:self.contentLabel];
    
    
    UILabel * subLabel = [UILabel new];
    
    subLabel.text = @"三室两厅  110m  精装";
    subLabel.textColor = ColorWithRGB(0x999999);
    subLabel.font = [UIFont systemFontOfSize:13 * SCREENH6];
    
    self.subLabel = subLabel;
    
    [self.contentView addSubview:self.subLabel];
    
    
    
    UIView * lineView = [UIView new];
    
    lineView.backgroundColor = ColorWithRGB(0xe6e6e6);
    
    self.lineView = lineView;
    
    [self.contentView addSubview:self.lineView];
}


- (void)layoutSubviews{
    
    [self.leftImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.contentView).offset(15 * SCREENH6);
        make.leading.mas_equalTo(self.contentView).offset(15 * SCREENH6);
        make.width.mas_equalTo(105 * SCREENH6);
        make.height.mas_equalTo(80 * SCREENH6);
    }];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.leftImageView);
        make.leading.mas_equalTo(self.leftImageView.mas_trailing).offset(10 * SCREENH6);
    }];
    
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.titleLabel);
        make.trailing.mas_equalTo(self.contentView).offset(-15 * SCREENH6);
        make.top.mas_equalTo(self.titleLabel.mas_bottom).offset(7 * SCREENH6);
    }];
    
    [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.contentLabel);
         make.top.mas_equalTo(self.contentLabel.mas_bottom).offset(7 * SCREENH6);
    }];
    
    [self.subLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.moneyLabel);
        make.top.mas_equalTo(self.moneyLabel.mas_bottom).offset(7 * SCREENH6);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.mas_equalTo(self.contentView);
        make.height.mas_equalTo(1 * SCREENH6);
        make.bottom.mas_equalTo(self.contentView);
    }];
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
